<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Colony Counter Analysis Report</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        .header {
            text-align: center;
            margin-bottom: 30px;
        }
        .summary {
            margin: 20px 0;
            padding: 20px;
            background-color: #f5f5f5;
            border-radius: 5px;
        }
        .stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin: 20px 0;
        }
        .stat-box {
            padding: 15px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .plots {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
            gap: 20px;
            margin: 20px 0;
        }
        .plot-container {
            text-align: center;
        }
        .plot-container img {
            max-width: 100%;
            height: auto;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }
        th, td {
            padding: 8px;
            border: 1px solid #ddd;
            text-align: left;
        }
        th {
            background-color: #f5f5f5;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>Colony Counter Analysis Report</h1>
        <p>Generated on: {{ datetime }}</p>
    </div>

    <div class="summary">
        <h2>Analysis Summary</h2>
        <p><strong>Image:</strong> {{ image_name }}</p>
        <p><strong>Analysis Type:</strong> {{ analysis_type }}</p>
        <p><strong>Analysis Time:</strong> {{ analysis_time }}</p>
    </div>

    <div class="stats">
        <div class="stat-box">
            <h3>Colony Count Statistics</h3>
            <p><strong>Mean Count:</strong> {{ mean_count:.1f }}</p>
            <p><strong>Standard Deviation:</strong> {{ std_count:.1f }}</p>
            <p><strong>CV (%):</strong> {{ cv:.1f }}</p>
            <p><strong>Range:</strong> {{ min_count }} - {{ max_count }}</p>
        </div>
        
        <div class="stat-box">
            <h3>Confidence Statistics</h3>
            <p><strong>Mean Confidence:</strong> {{ mean_confidence:.3f }}</p>
            <p><strong>Min Confidence:</strong> {{ min_confidence:.3f }}</p>
            <p><strong>Max Confidence:</strong> {{ max_confidence:.3f }}</p>
        </div>
    </div>

    <div class="plots">
        {% if plot_dist_path %}
        <div class="plot-container">
            <h3>Count Distribution</h3>
            <img src="{{ plot_dist_path }}" alt="Count Distribution">
        </div>
        {% endif %}
        
        {% if plot_seq_path %}
        <div class="plot-container">
            <h3>Count Sequence</h3>
            <img src="{{ plot_seq_path }}" alt="Count Sequence">
        </div>
        {% endif %}
    </div>

    {% if results_table %}
    <div class="results">
        <h2>Detailed Results</h2>
        {{ results_table|safe }}
    </div>
    {% endif %}

    <div class="footer">
        <p><small>Generated by Colony Counter v{{ version }}</small></p>
    </div>
</body>
</html>
